package com.kitty.mybatis.mybatisv1.binding;

import com.kitty.mybatis.mybatisv1.session.KittyConfiguration;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * @Description
 * @Author SHEN
 * @Date 2020/10/29
 */
public class KittyMethodSignature {

    private final boolean returnsMany;

    private final boolean returnsMap;

    private final boolean returnsViod;

    private final Class<?> returnsType;

    private final String mapKey;

    public KittyMethodSignature(KittyConfiguration configuration, Method method) {
        this.returnsType = method.getReturnType();
        this.returnsMany = false;
        this.returnsViod = void.class.equals(returnsType);
        this.mapKey = getMapKey(method);
        this.returnsMap = this.mapKey != null;
    }

    private String getMapKey(Method method){
        String mapKey = null;
        if (Map.class.isAssignableFrom(method.getReturnType())) {
            //如果返回类型是map类型的，查看该method是否有MapKey注解。如果有这个注解，将这个注解的值作为map的key
            /*final MapKey mapKeyAnnotation = method.getAnnotation(MapKey.class);
            if (mapKeyAnnotation != null) {
                mapKey = mapKeyAnnotation.value();
            }*/
        }
        return mapKey;
    }

    public Object convertArgsToSqlCommandParam(Object[] args) {
        //todo
        return null;
    }
}
